package Java8实战._2_Stream_使用流._6_数值流;

import org.junit.jupiter.api.Test;

import java.util.stream.IntStream;

public class _3_数值流应用_勾股数 {

    public static void main(String[] args) {
        IntStream.rangeClosed(1,100).boxed()
                .flatMap(a -> IntStream.rangeClosed(a,100)
                        .filter(b -> Math.sqrt(a * a + b * b) % 1 == 0)
                        .mapToObj(b -> new int[]{a,b,(int)Math.sqrt(a * a + b * b)})
                )
                .limit(5)
                .forEach(t -> System.out.println(t[0] + "," + t[1] + "," + t[2]));
    }

    @Test
    public void test(){
        IntStream.rangeClosed(1,100)
                    .boxed()
                    .flatMap(a -> IntStream.rangeClosed(a,100)
                            .filter(b -> Math.sqrt(a * a + b * b) % 1 == 0)
                            .boxed()
                            .map(b -> new int[]{a,b,(int)Math.sqrt(a * a + b * b)})
                    )
                    .forEach(ints -> System.out.println(ints[0] + ", " +ints[1] + ", " + ints[2]))
                    ;

    }

    @Test
    public void test1(){
        IntStream.rangeClosed(1,100).boxed()
                .flatMap(a ->
                            IntStream.rangeClosed(a, 100)
                                    .mapToObj(b -> new double[]{a, b, Math.sqrt(a * a + b * b)})
                                    .filter(ints -> ints[2] % 1 == 0)
                )
                .forEach(ints -> System.out.println(ints[0] + ", " +ints[1] + ", " + ints[2]))
                ;
    }
}













